<template>
	<view class="detail-view" :style="{ background: loading == 'nodata' ? 'none' : '#fff' }">
		<view class="top-bar"><uni-navbar :fixed="true" :back="true" color="#fff" title="讨论组详情"></uni-navbar></view>

		<!-- 内容详情 -->
		<view class="detail_con" v-if="groupInfo">
			<view class="a_group" v-if="groupInfo">
				<view class="a_img" v-if="groupInfo.logoPath"><image :src="$imagePathGroup(groupInfo.logoPath, groupInfo.logoName)" mode="aspectFill"></image></view>
				<view class="a_img" v-else :style="'background-color:' + groupInfo.logoColor">{{ groupInfo.groupName.slice(0, 4) }}</view>
				<view class="a_name">
					<view class="a_tit clamp">{{ groupInfo.groupName }}</view>
					<view class="a_jj clamp">共发起{{ issueCount }}个讨论议题，有{{ issueContentCount }}人次参与回答</view>
				</view>
			</view>
		</view>
		<view class="tab_list">
			<view class="tab_view" v-for="(item, index) in issueList" :key="item.id" @click="navTo('/pagesA/discussion/detail?id=' + item.id)">
				<view class="a_con">
					<view class="a_con_tit">{{ item.issue }}</view>
					<view class="a_con_status">
						<image class="status_img" :src="$imagePreview(item.proposerTouxiang)" mode="aspectFill"></image>
						<text class="status_name">{{ item.proposerName }}</text>
						<text class="status_lb">{{ item.jiebie }}</text>
						<text class="status_node st_end" v-if="item.nodeStatus == 2">已结束</text>
						<text class="status_node st_tlz" v-else>讨论中</text>
						<text class="status_node st_gly" v-if="item.isVisible == 0">仅管理员可见</text>
					</view>
				</view>
				<view class="a_tlz">
					<view class="a_tlz_p">
						<text class="a_tlz_name">{{ item.groupName }}</text>
						<text class="a_tlz_time">{{ item.createTime | parseTime('{y}-{m}-{d} {h}:{i}:{s}') }}</text>
					</view>
				</view>
			</view>
			<u-loadmore :status="loading" />
		</view>

		<u-back-top :scroll-top="scrollTop" top="200"></u-back-top>

		<view v-if="false && wlyzIssue && glyList && zyList"></view>
	</view>
</template>

<script>
import { mapState } from 'vuex';
export default {
	data() {
		return {
			scrollTop: 0,
			id: '',
			issueCount: 0,
			issueContentCount: 0,
			groupInfo: {},
			glyList: '',
			zyList: '',
			issueList: [],

			wlyzIssue: {
				groupName: '',
				status: 1,
				groupId: ''
			},
			loading: 'loadmore'
		};
	},
	onLoad(option) {
		this.loadLogin();
		this.id = option.id;
		this.wlyzIssue.groupId = option.id;
		this.loadGroup();
		this.loadData('refresh');
	},
	onPullDownRefresh() {
		this.loadGroup();
		this.loadData('refresh');
	},
	onReachBottom() {
		if (this.loading == 'loadmore') this.loadData('add');
	},
	onPageScroll(res) {
		this.scrollTop = res.scrollTop;
	},
	computed: {
		...mapState(['userInfo'])
	},
	methods: {
		loadLogin() {
			if (this.userInfo.Authorization) {
				this.clientCode = this.userInfo.sysUser.clientCode;
				this.userId = this.userInfo.sysUser.id;

				this.pageNum = 1;
				this.pageSize = 10;
			} else {
				this.$logout();
			}
		},
		loadGroup() {
			this.$request('/wlyz/group/query/' + this.id).then((res) => {
				this.issueCount = res.data.issueCount;
				this.issueContentCount = res.data.issueContentCount;
				this.groupInfo = res.data.wlyzGroup;
				this.glyList = res.data.glyList;
				this.zyList = res.data.zyList;
			});
		},
		loadData(type = 'add') {
			if (this.loading == 'loading') {
				return false;
			}
			if (type == 'add') {
				if (this.loading == 'nomore') {
					return false;
				}
				this.loading = 'loading';
			} else {
				this.loading = 'loading';
			}
			if (type != 'add') {
				this.pageNum = 1;
			}

			let data = {
				pageNum: this.pageNum,
				pageSize: this.pageSize,
				clientCode: this.clientCode,
				groupId: this.id,
				currentUserId: this.userId
			};
			data.wlyzIssue = this.wlyzIssue;
			this.$request('/wlyz/issue/list', data, {
				load: true
			}).then((res) => {
				let count = 0;
				if (type != 'add') {
					uni.stopPullDownRefresh();
					this.issueList = [];
				}
				this.loading = this.pageNum < Math.ceil(res.data.total / this.pageSize) ? 'loadmore' : 'nomore';
				this.pageNum = this.pageNum + 1;
				this.issueList = this.issueList.concat(res.data.records);
				this.loaded = true;
				if (this.issueList.length <= 0) {
					this.loading = 'nodata';
				}
			});
		},
		navTo(url) {
			uni.navigateTo({
				url: url
			});
		}
	}
};
</script>

<style lang="scss">
.detail-view {
	margin-bottom: 94rpx;
	background-color: #fff;
}

.tab_list {
	width: 100%;
	height: auto;

	.tab_view {
		width: 100%;
		padding: 34rpx 30rpx 26rpx;
		line-height: 1.4;
		border-bottom: 1rpx solid #f1f2f3;
		background-color: #fff;

		.a_con {
			color: #333333;

			.a_con_tit {
				font-size: 16px;
				width: 100%;
				display: -webkit-box;
				-webkit-box-orient: vertical;
				-webkit-line-clamp: 2;
				overflow: hidden;
			}

			.a_con_status {
				display: flex;
				align-items: center;
				width: 100%;
				line-height: 50rpx;
				font-size: 14px;
				margin: 14rpx 0 18rpx;
				color: #999;

				.status_img {
					flex-shrink: 0;
					margin-right: 12rpx;
					width: 50rpx;
					height: 50rpx;
					border-radius: 50%;
					overflow: hidden;
					background-color: #f1f2f3;
				}

				.status_name {
					flex-shrink: 0;
					margin-right: 12rpx;
					font-size: 14px;
				}

				.status_lb {
					margin: 0 8rpx;
					overflow: hidden;
					text-overflow: ellipsis;
					white-space: nowrap;
					/* position: relative;
					top: 0.3rem; */
				}

				.status_node {
					flex-shrink: 0;
					margin-left: auto;
					padding: 8rpx 20rpx;
					font-size: 13px;
					line-height: 1;
				}
			}

			.a_con_content {
				font-size: 14px;
				color: #333333;
				width: 100%;
				display: none;
			}
		}

		.a_tlz {
			color: #999;
			/* text-align: right; */

			.a_tlz_p {
				font-size: 13px;

				.a_tlz_name {
					display: inline-block;
					margin-right: 40rpx;
				}
			}
		}

		.a_group {
			display: flex;
			align-items: center;
			/* padding: 0 15rpx; */
			font-size: 16px;

			.a_img {
				display: flex;
				align-items: center;
				justify-content: center;
				flex-shrink: 0;
				width: 100rpx;
				height: 100rpx;
				border-radius: 50%;
				text-align: center;
				font-size: 14px;
				color: #ffffff;
				line-height: 1.2;
				background: #ff9900;

				image {
					width: 100rpx;
					height: 100rpx;
					border-radius: 50%;
				}
			}

			.a_name {
				padding-left: 26rpx;
				line-height: 1.2;
			}
		}
	}
}

.st_end {
	color: #999;
	border: 1rpx solid #999;
	border-radius: 10rpx;
}
.st_tlz {
	color: #ff0000;
	border: 1rpx solid #ff0000;
	border-radius: 10rpx;
}
.st_gly {
	margin-right: 10rpx;
	color: #ce1617;
	border: 1rpx solid #ce1617;
	border-radius: 10rpx;
}

.detail_con {
	padding: 20rpx 30rpx;
	color: #333333;
	border-bottom: 20rpx solid #f1f2f3;

	.a_group {
		display: flex;
		align-items: center;
		/* 	padding: 0 15rpx; */
		font-size: 16px;

		.a_img {
			display: flex;
			align-items: center;
			justify-content: center;
			flex-shrink: 0;
			width: 100rpx;
			height: 100rpx;
			border-radius: 50%;
			text-align: center;
			font-size: 28rpx;
			color: #ffffff;
			line-height: 1.2;
			background: #ff9900;

			image {
				width: 100rpx;
				height: 100rpx;
				border-radius: 50%;
			}
		}

		.a_name {
			padding-left: 26rpx;
			line-height: 1.2;
		}

		.a_tit {
			font-size: 16px;
			font-weight: bold;
			line-height: 48rpx;
		}

		.a_jj {
			font-size: 14px;
			color: #999;
			line-height: 42rpx;
		}
	}
}
</style>
